home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ncsa / Mac / Telnet2.6 / prerelease / d5 / Telnet 2.6.1d5.src.sit.hqx / Telnet 2.6.1d5 src / source / main / mainseg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-22  |  4.4 KB  |  164 lines

  1. /****************************************************************
  2. *    NCSA Telnet for the Macintosh                                *
  3. *                                                                *
  4. *    National Center for Supercomputing Applications                *
  5. *    Software Development Group                                    *
  6. *    152 Computing Applications Building                            *
  7. *    605 E. Springfield Ave.                                        *
  8. *    Champaign, IL  61820                                        *
  9. *                                                                *
  10. *    Copyright (c) 1986-1992,                                    *
  11. *    Board of Trustees of the University of Illinois                *
  12. ****************************************************************/
  13.  
  14. #ifdef MPW
  15. #pragma segment main
  16. #endif
  17.  
  18. #define GLOBALMASTER            /* Global structures are charged to us... see below */
  19. #include "TelnetHeader.h"
  20. #include "dialog_resrcdefs.h"
  21. #include "event.proto.h"
  22. #include "netevent.proto.h"
  23. #include "init.proto.h"
  24. #include "network.proto.h"        // For netshut proto
  25. #include "wind.h"
  26. #include "MacBinary.h"
  27. #include "binsubs.proto.h"            // For close_mb_files proto
  28.  
  29. #include "vgtek.proto.h"        // For TEKMAINunload proto
  30. #include "vr.h"                    // So vr.proto.h works (sigh)
  31. #include "vr.proto.h"            // For ICRunload proto
  32. #include "rsinterf.proto.h"        // For RSunload proto
  33. #include "vsem.proto.h"            // For VSunload proto
  34. #include "configure.proto.h"    // For CONFIGUREunload proto
  35. #include "macros.proto.h"        // For MACROSunload proto
  36. #include "bkgr.proto.h"            // For FTPServerUnload proto
  37. #include <Printing.h>            // So printing.proto.h doesn't die
  38. #include "printing.proto.h"        // For PrintingUnload proto
  39. #include "sets.proto.h"            // For SETSunload proto
  40. #include "ftpbin.proto.h"        // For FTPClientunload proto
  41. #include "rg0.proto.h"            // For TEKNULLunload proto
  42. #include "rgmp.proto.h"            // For TEKMacPicunload proto
  43. #include "maclook.proto.h"        // For MiscUnload proto
  44. #include "parse.proto.h"        // For Parseunload proto
  45.  
  46. #include "mainseg.proto.h"
  47.  
  48. //#define    PERFORMANCE                    //    Define to use MPW performance tools
  49. #ifdef    PERFORMANCE
  50. #include    <Perf.h>
  51. TP2PerfGlobals    ThePGlobals;
  52. #endif
  53.  
  54. //#define    PROFILER                        //    Define to use MW profiler
  55. #ifdef    PROFILER
  56. #include     "profiler.h"
  57. #endif
  58.  
  59. Cursor *theCursors[NUMCURS];        /* all the cursors in a nice bundle */
  60.  
  61. WindRec
  62.     *screens,        /* Window Records (VS) for :    Current Sessions */
  63.     *ftplog;
  64.  
  65. short scrn=0;
  66.  
  67. TelInfoRec    *TelInfo;            /* This is defined here and externed everywhere else. */
  68.  
  69. void    main(void)
  70. {
  71.     short    i;
  72.     long    lastCount = 0;
  73.     MaxApplZone();
  74.     
  75.     for (i=0; i<9; i++)
  76.         MoreMasters();
  77.         
  78. #ifdef    PERFORMANCE
  79.     ThePGlobals = nil;
  80.     if (!InitPerf(&ThePGlobals, 10, 8, TRUE, TRUE, "\pCODE", 0, "\p", FALSE, 0, 0, 0))
  81.         Debugger();
  82.     PerfControl(ThePGlobals, TRUE);
  83. #endif
  84. #ifdef    PROFILER
  85.     if (ProfilerInit(collectDetailed, microsecondsTimeBase, 1000, 30) != noErr)
  86.         DebugStr("\pError starting profiler!");
  87.     ProfilerSetStatus(false);
  88.     ProfilerClear();
  89. #endif
  90.     init();                    /* JMB 2.6 - Call all init routines */
  91.     UnloadSeg(&init);        /* Bye, bye to init routines...     */
  92.  
  93.     do {                        /* BYU - Do this forever */
  94.         UnloadSegments();
  95.         DoEvents();
  96.         if (!TelInfo->done) DoNetEvents();
  97.         if (TickCount() - lastCount > 1800) {            // Once every 30 seconds
  98.             CheckFreeMemory();
  99.             lastCount = TickCount();
  100.             }
  101.         } while (!TelInfo->done);                        /* BYU mod */
  102.         
  103. #ifdef    PERFORMANCE
  104.     if (!PerfDump(ThePGlobals, "\pPerform.out", TRUE, 80))
  105.         DebugStr("\pDump Failed");
  106.     Debugger(); 
  107.     TermPerf(ThePGlobals);
  108. #endif
  109. #ifdef    PROFILER
  110.     if (ProfilerDump("\pProfiler.out") != noErr) {
  111.         DebugStr("\pDump Failed");
  112.         }
  113.     ProfilerTerm();
  114. #endif
  115. }
  116.  
  117. void    quit( void)
  118. {
  119.     if (TelInfo->numwindows>0)
  120.         return;
  121.  
  122.     netshut();
  123.     CloseResolver();            /* BYU 2.4.16 */
  124.  
  125.     close_mb_files();            /* BYU - Don't leave any files open! */
  126.     TelInfo->done = 1;            /* BYU */
  127. }
  128.  
  129. void    forcequit(void)
  130. {
  131.     quit();
  132.     ExitToShell();
  133. }
  134.  
  135. //    This is rather simple right now, but I'll make it smarter when I have the time.
  136. void    CheckFreeMemory(void)
  137. {
  138.     long    space, block;
  139.     
  140.     PurgeSpace(&space, &block);
  141.     
  142.     if (space < (30 * 1024))
  143.         Alert(MemoryLowAlert, NULL);
  144. }
  145.  
  146. //    This unloads the segments that are safe to unload.  Right now, the DNR and network
  147. //    segments ARE NOT safe to unload.  Do _not_ add anything to this unless you really
  148. //    know what you are doing!  (I MEAN IT!)
  149. void    UnloadSegments(void)
  150. {
  151.     UnloadSeg(&Parseunload);
  152.     UnloadSeg(&TEKMAINunload);
  153.     UnloadSeg(&ICRunload);
  154.     UnloadSeg(&RSunload);
  155.     UnloadSeg(&VSunload);
  156.     UnloadSeg(&CONFIGUREunload);
  157.     UnloadSeg(&MACROSunload);
  158.     UnloadSeg(&FTPServerUnload);
  159.     UnloadSeg(&PrintingUnload);
  160.     UnloadSeg(&SETSunload);
  161.     UnloadSeg(&TEKNULLunload);
  162.     UnloadSeg(&TEKMacPicunload);
  163.     /* UnloadSeg(&MiscUnload); */    /* Don't bang on the disk (RW) */
  164. }